package com.neusoft.controller;

import com.neusoft.base.BaseController;
import com.neusoft.model.OrderSearch;
import com.neusoft.po.Order;
import com.neusoft.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 订单请求控制器
 *
 * @author Lucifer
 * @since 2021/5/16 18:43
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单接口")
public class OrderController extends BaseController {

    @Resource
    private OrderService orderService;

    @GetMapping("/{id}")
    @ApiOperation("单个订单")
    public Order page(@PathVariable("id") Integer id) {
        return orderService.one(id);
    }

    @PostMapping("/page")
    @ApiOperation("订单下的所有商品")
    public Object page(@RequestBody OrderSearch orderSearch) {
        return orderService.page(orderSearch);
    }

    @PostMapping("/page2")
    @ApiOperation("所有订单的分页数据")
    public Object page2(@RequestBody OrderSearch orderSearch) {
        return orderService.page2(orderSearch);
    }

    @PostMapping
    @ApiOperation("创建订单")
    public Integer save(@RequestBody Order order) {
        return orderService.save(order);
    }

    @PostMapping("/submit/{id}")
    @ApiOperation("提交订单")
    @ApiImplicitParam(value = "id", name = "订单ID", required = true)
    public Integer submit(@PathVariable("id") Integer id) {
        return orderService.submit(id);
    }

    @PostMapping("/pay/{id}")
    @ApiOperation("支付订单")
    @ApiImplicitParam(value = "id", name = "订单ID", required = true)
    public Integer pay(@PathVariable("id") Integer id) {
        return orderService.pay(id);
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("批量删除")
    public void delete(@PathVariable("ids") Integer[] ids) {
        orderService.deleteByIds(ids);
    }

}
